<?php
header("content-type:text/html;charset=utf8");
$oUsername = $_GET['oUser'];
$oPassword = $_GET['oPassword'];
$nUsername = $_GET['nUser'];
$nPassword = $_GET['nPassword'];
$con = mysqli_connect('localhost', 'root', 'root', 'userdata');
mysqli_query($con, 'set names utf8');

$res = mysqli_query($con, "select * from users where username='$oUsername' and password='$oPassword'");
$row = mysqli_fetch_assoc($res);

if ($row) {
    $res2 = mysqli_query($con, "update users set username='$nUsername',password='$nPassword' where username='$oUsername'");
    $res3 = mysqli_query($con, "update goods set user='$nUsername' where user='$oUsername'");
    if ($res2 && $res3) {
        $arr = [
            "meta" => [
                "status" => 1,
                "msg" => "修改成功"
            ]
        ];
    } else {
        $arr = [
            "meta" => [
                "status" => 2,
                "msg" => "修改失败"
            ]
        ];
    }
} else {
    $arr = [
        "meta" => [
            "status" => -1,
            "msg" => "旧密码不正确,请重新输入!"
        ]
    ];
}

echo json_encode($arr);
